﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using Quellenverwaltung.Data.Source;

namespace Quellenverwaltung.Entwicklungskomponenten
{
    public partial class XmlSerialization : Form
    {
        public XmlSerialization()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Sources sources = new Sources();

            Book book = new Book();
            sources.Books.Add(book);

            book.City = "Stuttgart";
            book.Edition = "1ste Auflage";
            book.Publisher = "Book Verlag";
            book.RefOrder = "Ref Order";
            book.ShortTitle = "kurztitel";
            book.StandardNumber = "ISBN 123444";
            book.Tag = "TAG23";
            book.Title = "Mein erstes Buch";
            book.Year = "2003";
            book.Volume = "Volume";
            book.Comments = "Kommentare";
            book.CountryRegion = "Region";
            book.Author = new Authors();
            book.Author.Author = new Author();

            Person person = new Person();
            person.First = "Nils";
            person.Last = "Mosbach";
            Person person2 = new Person();
            person2.First = "Timo";
            person2.Last = "Epple";
            book.Author.Author.NameList.Add(person);
            book.Author.Author.NameList.Add(person2);

            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
            namespaces.Add("b", "http://schemas.microsoft.com/office/word/2004/10/bibliography");

            XmlSerializer serializer = new XmlSerializer(typeof(Sources));
            TextWriter textWriter = new StreamWriter(@"I:\BookSource.xml");
            serializer.Serialize(textWriter, sources, namespaces);
            textWriter.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Sources));
            Sources sources = (Sources) serializer.Deserialize(new StreamReader(@"I:\BookSource.xml"));
            richTextBox1.Text = "Deserialisiert";
        }
    }
}
